home *** CD-ROM | disk | FTP | other *** search
/ Aminet 19 / Aminet 19 (1997)(GTI - Schatztruhe)[!][Jun 1997].iso / Aminet / gfx / board / Graffiti_lib.lha / Graffiti / graffiti.h < prev    next >
C/C++ Source or Header  |  1997-03-29  |  10KB  |  240 lines

  1. #ifndef GRAFFITI_H
  2. #define GRAFFITI_H
  3.  
  4. /*
  5.     (C) 1997 by A. Digulla
  6.     All rights reserved.
  7. */
  8. #ifndef EXEC_LISTS_H
  9. #   include <exec/lists.h>
  10. #endif
  11. #ifndef UTILITY_TAGITEM_H
  12. #   include <utility/tagitem.h>
  13. #endif
  14.  
  15. struct GraffitiHandle
  16. {
  17.     /* Currently installed colormap for the graffiti */
  18.     struct GraffitiColorMap
  19.     {
  20.     UBYTE F, R, G, B;
  21.     } ColorMap[256];
  22.  
  23.     UBYTE FG, BG;
  24.  
  25.     /* Functions of the graffiti */
  26.     UBYTE (*FindBestMatch)(struct GraffitiHandle * gh, UBYTE r, UBYTE g, UBYTE b);
  27.     UBYTE (*GetPixel)(struct GraffitiHandle * gh, WORD x, WORD y);
  28.     void (*SetPixel)(struct GraffitiHandle * gh, WORD x, WORD y);
  29.     void (*SetPixelColor)(struct GraffitiHandle * gh, WORD x, WORD y, UBYTE col);
  30.     void (*DrawPixel)(struct GraffitiHandle * gh, WORD x, WORD y, struct GraffitiHookData * ghd);
  31.     void (*SetPixel3D)(struct GraffitiHandle * gh, WORD x, WORD y, WORD z);
  32.     void (*SetPixel3DColor)(struct GraffitiHandle * gh, WORD x, WORD y, WORD z, UBYTE col);
  33.     void (*DrawPixel3D)(struct GraffitiHandle * gh, WORD x, WORD y, WORD z, struct GraffitiHookData * ghd);
  34.     void (*DrawRect)(struct GraffitiHandle * gh, WORD x1, WORD y1, WORD x2, WORD y2);
  35.     void (*FillRect)(struct GraffitiHandle * gh, WORD x1, WORD y1, WORD x2, WORD y2);
  36.     void (*DrawLine)(struct GraffitiHandle * gh, WORD x1, WORD y1, WORD x2, WORD y2);
  37.     void (*DrawEllipse)(struct GraffitiHandle * gh, WORD x1, WORD y1, WORD rx, WORD ry);
  38.     void (*FillEllipse)(struct GraffitiHandle * gh, WORD x1, WORD y1, WORD rx, WORD ry);
  39.     void (*DrawGenEllipse)(struct GraffitiHandle * gh, WORD x1, WORD y1, WORD rx, WORD ry, WORD w);
  40.     void (*FillGenEllipse)(struct GraffitiHandle * gh, WORD x1, WORD y1, WORD rx, WORD ry, WORD w);
  41.     void (*DrawText)(struct GraffitiHandle * gh, WORD x, WORD y, STRPTR text, UWORD len);
  42.     void (*FillText)(struct GraffitiHandle * gh, WORD x, WORD y, STRPTR text, UWORD len);
  43.  
  44.     /* Filter for rendering */
  45.     struct List * FilterList;
  46.  
  47.     /* Private data follow */
  48. };
  49.  
  50. /* Color definition for the Graffiti. Use in filter hooks. */
  51. /* Background= 0xFF000000, Fillcolor=0xFFFFFFFF */
  52. struct GraffitiColor
  53. {
  54.     UBYTE Alpha;    /* 0: Opaque, 0xFF: Transparent */
  55.     UBYTE R, G, B;
  56. };
  57.  
  58. /* This structure is passed as the message to each filter hook. */
  59. struct GraffitiHookData
  60. {
  61.     UWORD Cmd; /* Do not use */
  62.     UBYTE col; /* Current color. May be changed by the hook. Is restored
  63.           for each call to the hook. */
  64.     UBYTE pad0;
  65.     UWORD x1, y1, z1, x2, y2, z2;
  66.         /* Coordinates passed to the rendering function.
  67.         For lines and rectangles, these are the starting points.
  68.         For ellises, the radii are passed in x2 and y2.
  69.         For points, x2 and y2 are undefined.
  70.         3D plots will also use z1 and z2. */
  71.     UWORD x, y, z; /* Current position relative to x1 and y1. 0 <= x < x2-x1
  72.         and 0 <= y < y2-y1, if x2 and y2 are defined. If they are
  73.         not, then x and y are undefined. */
  74.     ULONG arg0; /* Arguments passed to the filter hook. */
  75.     ULONG arg1;
  76.     ULONG arg2;
  77.     ULONG arg3;
  78. };
  79.  
  80. /* Tags for Graffiti_Init() */
  81. #define GRAFFITI_TAGBASE    (TAG_USER)
  82. #define GTI_RESOLUTION        (GRAFFITI_TAGBASE + 1)  /* I.G GRAFFITI_RES_* */
  83. #define GTI_OVERSCAN        (GRAFFITI_TAGBASE + 2)  /* ISG ULONG */
  84. #define GTI_WIDTH        (GRAFFITI_TAGBASE + 3)  /* ISG ULONG */
  85. #define GTI_HEIGHT        (GRAFFITI_TAGBASE + 4)  /* ISG ULONG */
  86. #define GTI_MINWIDTH        (GRAFFITI_TAGBASE + 5)  /* ..G ULONG */
  87. #define GTI_MINHEIGHT        (GRAFFITI_TAGBASE + 6)  /* ..G ULONG */
  88. #define GTI_MAXWIDTH        (GRAFFITI_TAGBASE + 7)  /* ..G ULONG */
  89. #define GTI_MAXHEIGHT        (GRAFFITI_TAGBASE + 8)  /* ..G ULONG */
  90. #define GTI_LEFT        (GRAFFITI_TAGBASE + 9)  /* ISG ULONG */
  91. #define GTI_TOP         (GRAFFITI_TAGBASE + 10) /* ISG ULONG */
  92. #define GTI_BUFFER        (GRAFFITI_TAGBASE + 11) /* I.G GRAFFITI_BUFFER_* */
  93. #define GTI_3D            (GRAFFITI_TAGBASE + 12) /* ISG BOOL */
  94.  
  95. #define GRAFFITI_RES_80     0x0000 /* Use at most of these */
  96. #define GRAFFITI_RES_160    0x0001
  97. #define GRAFFITI_RES_320    0x0002
  98. #define GRAFFITI_RES_640    0x0003
  99. #define GRAFFITI_RES_MASK   0x0003 /* private */
  100.  
  101. #define GRAFFITI_RES_LACE   0x8000 /* Can be ORed to any resolution */
  102.  
  103. /*
  104.     Buffermodes.
  105.  
  106.     Use singlebuffer if you need no buffering.
  107.  
  108.     Use doublebuffer if you want to display one frame and render in the
  109.     background.
  110.  
  111.     Use triplebuffering for a steady stream if rendering needs sometimes
  112.     more and sometimes less time that displaying one frame.
  113.  
  114.     Use Multibuffering to let the Graffiti lib try to display a stready
  115.     frame rate. The Graffiti will allocate a new frame each time you call
  116.     Graffiti_UseNextBuffer() and free them when they have been displayed.
  117. */
  118. #define GRAFFITI_BUFFER_SINGLE      0x0001 /* Singlebuffer */
  119. #define GRAFFITI_BUFFER_DOUBLE      0x0002 /* Doublebuffering. */
  120. #define GRAFFITI_BUFFER_TRIPLE      0x0003 /* Triplebuffering. */
  121. #define GRAFFITI_BUFFER_MULTI      0x0004 /* Multibuffering. Not available yet. */
  122.  
  123. /* Prototypes */
  124.     /* Init the card */
  125. extern struct GraffitiHandle * Graffiti_Init (Tag tag, ...);
  126. extern struct GraffitiHandle * Graffiti_InitA (struct TagItem *);
  127. extern BOOL Graffiti_GetAttr (struct GraffitiHandle *, Tag tag, ULONG * attr);
  128. extern BOOL Graffiti_SetAttrs (struct GraffitiHandle *, Tag tag, ...);
  129. extern BOOL Graffiti_SetAttrsA (struct GraffitiHandle *, struct TagItem *);
  130. extern void Graffiti_Exit (struct GraffitiHandle * gh);
  131.  
  132. /* Rendering Macros */
  133.     /* Draw a pixel. Graffiti_SetPixel() ignores installed filters,
  134.     Graffiti_DrawPixel() uses them. If none are installed,
  135.     Graffiti_DrawPixel() does the same as Graffiti_SetPixel() */
  136. #define Graffiti_SetPixel(gh,x,y) \
  137.     (*(gh->SetPixel))(gh,x,y)
  138. #define Graffiti_DrawPixel(gh,x,y,ghd) \
  139.     (*(gh->DrawPixel))(gh,x,y,ghd)
  140. #define Graffiti_SetPixelColor(gh,x,y,c) \
  141.     (*(gh->SetPixelColor))(gh,x,y,c)
  142. #define Graffiti_SetPixel3D(gh,x,y,z) \
  143.     (*(gh->SetPixel3D))(gh,x,y,z)
  144. #define Graffiti_DrawPixel3D(gh,x,y,z,ghd) \
  145.     (*(gh->DrawPixel3D))(gh,x,y,z,ghd)
  146. #define Graffiti_SetPixel3DColor(gh,x,y,z,c) \
  147.     (*(gh->SetPixel3DColor))(gh,x,y,z,c)
  148.  
  149.     /* Get the current value for a pixel. To get the RGB values for that
  150.     pixel, use the value returned here as an index into the
  151.     Graffiti colormap above. */
  152. #define Graffiti_GetPixel(gh,x,y) \
  153.     (*(gh->GetPixel))(gh,x,y)
  154.  
  155.     /* Install and remove cliprect */
  156. void Graffiti_SetClip (struct GraffitiHandle * gh, UWORD left, UWORD top,
  157.     UWORD right, UWORD bottom);
  158.  
  159.     /* Render misc. primitives */
  160. #define Graffiti_DrawRect(gh,x1,y1,x2,y2) \
  161.     (*(gh->DrawRect))(gh,x1,y1,x2,y2)
  162. #define Graffiti_FillRect(gh,x1,y1,x2,y2) \
  163.     (*(gh->FillRect))(gh,x1,y1,x2,y2)
  164. #define Graffiti_RectFill   Graffiti_FillRect  /* Amiga compat :-) */
  165. #define Graffiti_DrawLine(gh,x1,y1,x2,y2) \
  166.     (*(gh->DrawLine))(gh,x1,y1,x2,y2)
  167. #define Graffiti_DrawEllipse(gh,x1,y1,rx,ry) \
  168.     (*(gh->DrawEllipse))(gh,x1,y1,rx,ry)
  169. #define Graffiti_FillEllipse(gh,x1,y1,rx,ry) \
  170.     (*(gh->FillEllipse))(gh,x1,y1,rx,ry)
  171. #define Graffiti_DrawText(gh,x,y,t,l) \
  172.     (*(gh->DrawText))(gh,x,y,t,l)
  173.  
  174.     /* Render a general ellipse. a is the rotation angle (0..32767).
  175.     0 means aligned to the x axis (equivalent to Graffiti_FillEllipse())
  176.     8192 means vertical (equivalent to 90 degrees), 4096 means
  177.     45 degrees. Rotation is counterclockwise. */
  178. #define Graffiti_DrawGenEllipse(gh,x1,y1,rx,ry,a) \
  179.     (*(gh->DrawGenEllipse))(gh,x1,y1,rx,ry,a)
  180. #define Graffiti_FillGenEllipse(gh,x1,y1,rx,ry,a) \
  181.     (*(gh->FillGenEllipse))(gh,x1,y1,rx,ry,a)
  182.  
  183.     /* Color functions */
  184.     /* Find the best matching Graffiti color for an RGB triple */
  185. #define Graffiti_FindBestMatch(gh,r,g,b) \
  186.     (*(gh->FindBestMatch))(gh,r,g,b)
  187.     /* Palette with grey, red, green and blue parts each from 0 to 255
  188.         in 64 steps */
  189. extern void Graffiti_InstallDefaultPalette (struct GraffitiHandle * gh);
  190.     /* Palette with grey, red, green, blue, cyan, magenta, yellow from
  191.         0 to 255 in 32 steps */
  192. extern void Graffiti_InstallPalette1 (struct GraffitiHandle * gh);
  193.     /* Palette with 3bit red, 3bit green and 2bit blue but without
  194.        real grey values. */
  195. extern void Graffiti_InstallPalette2 (struct GraffitiHandle * gh);
  196.     /* Palette with 7 steps of red, 7 steps of green and 5 steps of
  197.         blue in all combinations and 13 real grey values. */
  198. extern void Graffiti_InstallPalette3 (struct GraffitiHandle * gh);
  199.     /* Change foreground color */
  200. #define Graffiti_SetFG(gh,fg) gh->FG = fg
  201.     /* Change background color */
  202. #define Graffiti_SetBG(gh,bg) gh->BG = bg
  203.  
  204.     /* Control the Graffiti */
  205.     /* Begin command sequence */
  206. extern void Graffiti_BeginCmd (struct GraffitiHandle * gh);
  207.     /* Send commands as a block */
  208. extern void Graffiti_EndCmd (struct GraffitiHandle * gh);
  209.     /* Do nothing */
  210. extern void Graffiti_Nop (struct GraffitiHandle * gh);
  211.     /* Set Graffiti Mask register. This value is ANDed with every
  212.         pixel value in the graphic. */
  213. extern void Graffiti_SetMask (struct GraffitiHandle * gh, UBYTE mask);
  214.     /* Change a color of the graffiti */
  215. extern void Graffiti_SetRGB (struct GraffitiHandle * gh, UBYTE col, UWORD r, UWORD g,
  216.     UWORD b);
  217.  
  218.     /* Buffers */
  219.     /* Display next buffer. Will do nothing if the next buffer is the
  220.         one we currently render into. For singlebuffer, this will do
  221.         nothing. For doublebuffer, you must call
  222.         Graffiti_UseNextBuffer() first. For triplebuffer, just make
  223.         sure that you render in one of the next buffers. For multibuffer,
  224.         the next finished buffer will be displayed and the current
  225.         buffer will be freed. */
  226. BOOL Graffiti_ShowNextBuffer (struct GraffitiHandle * gh);
  227.     /* Now render in the next buffer. Note that if rendering is faster
  228.         than displaying (ie. you display a fixed rate of 50fps but
  229.         render 60fps) then you might render into a buffer which
  230.         is currently displayed if you use a mode with a fixed number
  231.         of buffers. */
  232. BOOL Graffiti_UseNextBuffer (struct GraffitiHandle * gh);
  233.  
  234.     /* IntuiMessage handling */
  235. struct IntuiMessage * Graffiti_CheckEvent (struct GraffitiHandle * gh);
  236. struct IntuiMessage * Graffiti_WaitEvent (struct GraffitiHandle * gh);
  237.  
  238. #endif /* GRAFFITI_H */
  239.  
  240.